﻿using Petaframe.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Petaframe.DataAccess.UnitTest.helpers;
using SharpTestsEx;

namespace Petaframe.DataAccess.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for TableQueriesTestSqlServer and is intended
    ///to contain all TableQueriesTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TableQueriesTestSqlServer : ClassPropertyAndInfoTestBase
    {
        /// <summary>
        ///A test for TableQueries Constructor
        ///</summary>
        [TestMethod()]
        public void TableQueriesConstructorTest()
        {
           
            TableQueries target = new TableQueries(expectedTableInfo);
            target.Should().Not.Be.Null();
        }

       
        [TestMethod()]
        public void DeleteQueryTest()
        {           
            TableQueries target = new TableQueries(expectedTableInfo);
            const string expected = "delete from [Categories] where CategoryID=@p0";
            string actual = target.DeleteQuery;
            expected.Should().Be.EqualTo(actual);
        }

        [TestMethod]
        public void DeleteThrowsIfNoPrimaryKey()
        {
            TableInfo dummyInfo = new TableInfo();
            TableQueries target = new TableQueries(dummyInfo);
            target.Executing(z => z.DeleteQuery.ToString()).Throws();

        }
       
        [TestMethod()]
        public void InsertQueryTest()
        {
            TableQueries target = new TableQueries(expectedTableInfo);
            const string expected = "insert into [Categories] (CategoryName, Description) values (@p1, @p2)";
            string actual = target.InsertQuery;
            expected.Should().Be.EqualTo(actual);
        }

     

        /// <summary>
        ///A test for UpdateQuery
        ///</summary>
        [TestMethod()]
        public void UpdateQueryTest()
        {
            TableQueries target = new TableQueries(expectedTableInfo);
            const string expected = "update [Categories] set CategoryName=@p1, Description=@p2 where CategoryID=@p0";
            string actual = target.UpdateQuery;
            expected.Should().Be.EqualTo(actual);
        }

        [TestMethod]
        public void UpdateThrowsIfNoPrimaryKey()
        {

            TableInfo dummyInfo = new TableInfo();
            TableQueries target = new TableQueries(dummyInfo);
            target.Executing(z => z.UpdateQuery.ToString()).Throws();
        }
    
    }
}
